﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySoft.Data;

namespace Caifu.Datas
{
	/// <summary>
	/// 基金托管人
	/// </summary>
	public class TrusteeData
	{
		/// <summary>
		/// 实例
		/// </summary>
		public static readonly TrusteeData Instance = new TrusteeData();

		private readonly DbSession dbSession = new DbSession("Caifu");

		/// <summary>
		/// 新增基金托管人
		/// </summary>
		/// <param name="Trustee"></param>
		public void AddTrustee(Trustee Trustee)
		{
			Trustee.Detach();
			if (Trustee.Id == Guid.Empty) Trustee.Id = Itfort.Comb.NewComb();
			if (Trustee.AddTime == DateTime.MinValue) Trustee.AddTime = DateTime.Now;
			if (Trustee.UpdateTime == DateTime.MinValue) Trustee.UpdateTime = DateTime.Now;
			dbSession.Save<Trustee>(Trustee);
		}

		/// <summary>
		/// 修改基金托管人
		/// </summary>
		/// <param name="Trustee"></param>
		public void UpdateTrustee(Trustee Trustee)
		{
			Trustee.Attach();
			Trustee.UpdateTime = DateTime.Now;
			dbSession.Save<Trustee>(Trustee);
		}

		/// <summary>
		/// 删除基金托管人
		/// </summary>
		/// <param name="id"></param>
		public void DeleteTrustee(Guid id)
		{
			dbSession.Delete<Trustee>(id);
		}

		/// <summary>
		/// 获取基金托管人
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		public Trustee GetTrustee(Guid id)
		{
			return dbSession.Single<Trustee>(id);
		}

		/// <summary>
		/// 获取基金托管人
		/// </summary>
		/// <param name="pageIndex"></param>
		/// <param name="pageSize"></param>
		/// <returns></returns>
		public IList<Trustee> GetTrustees(Int32 pageIndex, Int32 pageSize)
		{
			return dbSession.From<Trustee>()
				.GetPage(pageSize).ToList(pageIndex);
		}
	}
}

